<!-- 首页 -->
<template>
    <view class="home-wrap u-m-b-20" v-show="userInfo.password">
        <!-- 空白页 -->
        <!--    搜索-->
        <view class="u-sticky-wrap">
            <view class="head_box u-flex u-sticky u-flex-col"
                  :style="{ position: 'fixed', top: stickyTop + 'px', left: '0px', width:'100%', zIndex: 99 ,'background-color':'#f8f8f8',padding:'0 30rpx 0'}"
            >
                <view class="u-flex u-row-left u-col-center" style="width: 90%;">
                    <view style="width: 15%;">手机号</view>
                    <u-search style="width: 88%;" v-model="searchVal" :clearabled="true" :bg-color="'#fff'" :search-icon-color="'#333'" :color="'#333'" :placeholder-color="'#A8A9A9'" :show-action='false' margin="20rpx 0rpx 0rpx 20rpx" placeholder="输入手机号" height="64"></u-search>

                </view>
                <view class="u-flex u-row-left u-col-center" style="width: 90%;">
                    <view style="width: 15%;">地区</view>
                    <u-input type="select" :clearabled="true" :select-open="showRegin" class="input-item u-p-l-10" style="width: 88%;" v-model="area_text" :placeholder-color="'#A8A9A9'" placeholder="选择地区" @click="showareas()"/>
                    <!-- 省市区选择器 -->
                    <u-select v-if="areaData.length>0" mode="mutil-column-auto" safe-area-inset-bottom :list="areaData" v-model="showRegin" @confirm="regionConfirm"></u-select>

                </view>
                <view class="bianji u-p-14 u-m-b-20 u-flex u-row-center u-col-center" @click="changeedit()">
                    {{ '查询' }}
                </view>
            </view>
        </view>

        <view class="content-box" style="margin-top: 270rpx">
            <view class="userInfo u-flex u-row-between u-col-center">
                <view class="userleft u-flex u-row-left u-col-center">
                    <image class="u-m-r-10" style="width: 40rpx;height: 20rpx;" src="/static/images/biaoshi.png"></image>
                    <view class="usertitle">客户信息({{ total > 0 ? total : 0 }})</view>
                </view>
                <view class="userright" v-if="userInfo&&userInfo.group_id=='2'" @click="goFenPei()">选择分配员工</view>
            </view>
            <view v-if="!isEmpty">
                <u-checkbox-group @change="checkboxGroupChange" :wrap="true" v-if="userInfo&&userInfo.group_id=='2'">
                    <u-checkbox
                        v-model="goods.checked"
                        v-for="(goods, index) in mykehuList" :key="index"
                        :name="goods.customers_id"
                    >
                        <view class="collect-list" @tap.stop="jump('/pages/kehu/mykehudetail',{customers_id:goods.customers_id})">
                            <view class="zixun-item u-flex u-flex-col u-p-20 u-m-t-20">
                                <view class="u-flex u-row-between u-col-center u-w-100s u-m-b-20 u-p-b-20" style="border-bottom: 2rpx solid #f8f8f8">
                                    <view class="u-flex u-row-left" style="width: 90%;">
                                        <view class="user_img u-m-r-10">
                                            <image style="width: 80rpx;height: 80rpx;border-radius: 50%" src="/static/images/logo.jpg"></image>
                                        </view>
                                        <view class="zixuntitle u-ellipsis-1">{{ goods.customer_names }}</view>
                                        <view class="zixuntitle u-ellipsis-1 u-m-l-10">{{ goods.phones }}</view>
                                    </view>
                                    <u-icon name="phone-fill" color="#4FF279" size="36" @tap.stop="telphone(goods.phone)"></u-icon>
                                </view>
                                <view class="u-flex u-row-between u-flex-col u-col-center u-w-100s u-m-b-20">
                                    <view class="u-flex u-row-left u-m-b-20" style="width: 100%;">
                                        <view class="kehulsit">{{ '所在地区' }}:</view>
                                        <view class="kehulsit u-ellipsis-1 u-m-l-10" style="font-size: 28rpx;font-weight: bold">
                                            {{ goods.address }}
                                        </view>
                                    </view>
                                    <view class="u-flex u-row-left u-m-b-20" style="width: 100%;">
                                        <view class="kehulsit">{{ '职业信息' }}:</view>
                                        <view class="kehulsit u-ellipsis-1 u-m-l-10" style="font-size: 28rpx;font-weight: bold">
                                            {{ goods.staff_name }}
                                        </view>
                                    </view>
                                    <view class="u-flex u-row-left u-m-b-20" style="width: 100%;">
                                        <view class="kehulsit">{{ '标签信息' }}:</view>
                                        <view class="kehulsit u-flex u-m-l-10">
                                            <view class="tag" v-for="(tags,tagInd) in goods.car_tag" :style="{background:colorArr[tagInd]}">
                                                {{ tags }}
                                            </view>
                                        </view>
                                    </view>
                                </view>
                            </view>
                        </view>
                    </u-checkbox>
                </u-checkbox-group>
                <view v-else
                    v-model="goods.checked"
                    v-for="(goods, index) in mykehuList" :key="index"
                >
                    <view class="collect-list" @tap.stop="jump('/pages/kehu/mykehudetail',{customers_id:goods.customers_id})">
                        <view class="zixun-item u-flex u-flex-col u-p-20 u-m-t-20">
                            <view class="u-flex u-row-between u-col-center u-w-100s u-m-b-20 u-p-b-20" style="border-bottom: 2rpx solid #f8f8f8">
                                <view class="u-flex u-row-left" style="width: 90%;">
                                    <view class="user_img u-m-r-10">
                                        <image style="width: 80rpx;height: 80rpx;border-radius: 50%" src="/static/images/logo.jpg"></image>
                                    </view>
                                    <view class="zixuntitle u-ellipsis-1">{{ goods.customer_names }}</view>
                                    <view class="zixuntitle u-ellipsis-1 u-m-l-10">{{ goods.phones }}</view>
                                </view>
                                <u-icon name="phone-fill" color="#4FF279" size="36" @tap.stop="telphone(goods.phone)"></u-icon>
                            </view>
                            <view class="u-flex u-row-between u-flex-col u-col-center u-w-100s u-m-b-20">
                                <view class="u-flex u-row-left u-m-b-20" style="width: 100%;">
                                    <view class="kehulsit">{{ '所在地区' }}:</view>
                                    <view class="kehulsit u-ellipsis-1 u-m-l-10" style="font-size: 28rpx;font-weight: bold">
                                        {{ goods.address }}
                                    </view>
                                </view>
                                <view class="u-flex u-row-left u-m-b-20" style="width: 100%;">
                                    <view class="kehulsit">{{ '职业信息' }}:</view>
                                    <view class="kehulsit u-ellipsis-1 u-m-l-10" style="font-size: 28rpx;font-weight: bold">
                                        {{ goods.staff_name }}
                                    </view>
                                </view>
                                <view class="u-flex u-row-left u-m-b-20" style="width: 100%;">
                                    <view class="kehulsit">{{ '标签信息' }}:</view>
                                    <view class="kehulsit u-flex u-m-l-10">
                                        <view class="tag" v-for="(tags,tagInd) in goods.car_tag" :style="{background:colorArr[tagInd]}">
                                            {{ tags }}
                                        </view>
                                    </view>
                                </view>
                            </view>
                        </view>
                    </view>
                </view>
            </view>
            <!-- 权限验证 -->
            <u-popup v-model="showTetel" mode="center" border-radius="20" :closeable="true" close-icon-pos="top-right">
                <view class="notice-modal">
                    <view class="notice-title">{{ "是否拨打" + telenum }}</view>
                    <view class="u-flex u-row-around u-w-100s">
                        <button class="u-reset-button back-btn" @tap="showTetel=false">取消</button>
                        <button class="u-reset-button notice-btn" @tap="$tools.callPhone(telenum)">确认</button>

                    </view>
                </view>
            </u-popup>
            <!-- 数据为空 -->
            <shopro-empty v-if="isEmpty" :image="$IMG_URL + '/imgs/empty/empty_cart.png'" tipText="暂时没有客户~">
            </shopro-empty>
            <!-- 更多 -->
            <u-loadmore v-show="!isEmpty" height="80rpx" :status="loadStatus" icon-type="flower" color="#ccc"/>
        </view>
        <u-popup v-model="showModal" mode="bottom" :closeable="true" close-icon-pos="top-right">
            <view class="modal-box page_box">
                <view class="modal-head u-flex u-row-center">
                    <text class="head-title">选择分配员工</text>
                </view>
                <view class="modal-content content_box y-f u-flex u-col-top u-m-t-30 u-m-b-100 u-row-between">
                    <view class="into-item u-flex u-row-between u-col-center u-flex-col u-m-t-20  u-w-100s">
                        <view class="u-flex u-w-100s u-m-b-20">
                            <u-search style="width: 88%;" v-model="searchstaffVal" :clearabled="true" :bg-color="'#f8f8f8'" :search-icon-color="'#333'" :color="'#333'" :placeholder-color="'#A8A9A9'" :show-action='false' placeholder="输入手机号" height="64"></u-search>
                            <text class="into-name" @click="getmyAllGroupList">搜索</text>
                        </view>
                        <u-radio-group v-model="fenPeiRen" @change="radioGroupChange" class="u-w-100s">
                            <u-radio
                                v-for="(goods, index) in myGroupAllList" :key="index"
                                :name="goods.user_id"
                                class="yuangonglist"
                            >
                                <view class="zixun-item u-flex u-flex-col u-p-20 u-m-t-20  u-w-100s">
                                    <view class="u-flex u-row-between u-col-center u-w-100s">
                                        <view class="u-flex u-row-left" style="width: 70%;">
                                            <view class="user_img u-m-r-10">
                                                <image style="width:80rpx;height:80rpx;border-radius:50%" src="/static/images/logo.jpg"></image>
                                            </view>
                                            <view class="zixuntitle u-ellipsis-1">{{ goods.name }}</view>
                                        </view>
                                        <view class="tag u-m-l-10" v-if="goods.position"
                                              :style="{borderColor:goods.position=='业务经理'?colorArr[0]:(goods.position=='职能员工'?colorArr[1]:(goods.position=='业务员'?colorArr[2]:(goods.position=='业务主管'?colorArr[3]:(goods.position=='人事经理'?colorArr[4]:(goods.position=='公司高管'?colorArr[5]:colorArr[6]))))),color:goods.position=='业务经理'?colorArr[0]:(goods.position=='职能员工'?colorArr[1]:(goods.position=='业务员'?colorArr[2]:(goods.position=='业务主管'?colorArr[3]:(goods.position=='人事经理'?colorArr[4]:(goods.position=='公司高管'?colorArr[5]:colorArr[6])))))}">
                                            {{ goods.position }}
                                        </view>
                                    </view>
                                    <view class="u-flex u-row-between u-w-100s">
                                        <view class="zixuntime u-p-t-10 u-p-b-10">{{ goods.mobile }}</view>
                                    </view>
                                </view>
                            </u-radio>
                        </u-radio-group>
                    </view>
                </view>
                <view class="modal-foot u-flex u-row-center u-col-center">
                    <view class="u-flex u-row-around u-w-100s">
                        <button class="u-reset-button back-btn" @tap="showModal=false">取消</button>
                        <button class="u-reset-button notice-btn" @tap="fenpeiSubmit">确认</button>

                    </view>
                </view>
            </view>
        </u-popup>
    </view>
</template>

<script>

let systemInfo = uni.getSystemInfoSync();
import {mapMutations, mapActions, mapState, mapGetters} from 'vuex';

export default {
    components: {},
    data() {
        return {

            showModal     : false,
            showRegin     : false,
            showTetel     : false,
            telenum       : '18135140898',
            keyword       : '',
            mykehuList    : [],
            isEmpty       : false,
            searchVal     : '',
            area_text     : '',
            loadStatus    : 'loadmore', //loadmore-加载前的状态，loading-加载中的状态，nomore-没有更多的状态
            currentPage   : 1,
            lastPage      : 1,
            stickyTop     : 0,
            show          : false,
            colorArr      : ['#00BFFF', '#4ff279', '#FFC1C1', '#E066FF', '#BFEFFF'],
            myGroupAllList: [],
            mykehuAllList : [],
            fenPeiRen     : '',
            total         : '',
            searchstaffVal: ''
        };
    },
    computed: {
        ...mapGetters(['areaData', 'userInfo']),
    },
    created() {
        this.getmyAllGroupList();
        // 触底监听
        uni.$on('uOnReachBottom', data => {
            if (this.currentPage < this.lastPage) {
                this.currentPage += 1;
                this.getmyKehuList();
            }
        });
    },
    onPullDownRefresh() {
        // this.init();
    },
    oonPageScroll(e) {

    },
    onShow() {
        let that = this;
        console.log("===areaData", this.userInfo)
        this.currentPage = 1;
        this.mykehuList  = [];
        this.getmyAllGroupList();
        this.getmyKehuList();
    },
    onHide() {

    },
    onLoad() {
        console.log("===areaData", this.areaData)
    },
    mounted() {
    },

    watch  : {},
    methods: {
        onSearch() {

        },
        showareas() {
            this.showRegin = true
            console.log("===areaData", this.areaData)
        },
        goFenPei() {
            if(this.choosedkehu){
                this.showModal = true
            }else{
                this.$u.toast('请选择勾选客户再进行分配')
            }
        },
        checkboxGroupChange(e) {
            console.log("====33ee", e)
            this.choosedkehu = e.join(',')
        },
        fenpeiSubmit() {
            let that = this;
            that.$http('login.distribution', {
                c_id: this.choosedkehu,
                s_id: this.fenPeiRen
            }, '加载中···').then(res => {
                if (res.code === 1) {
                    this.$u.toast(res.msg)
                    this.showModal=false
                }
            });
        },
        radioGroupChange() {
            console.log("===fenPeiRen", this.fenPeiRen)
        },

        // 组织成员列表
        getmyAllGroupList() {
            let that = this;
            that.$http('login.staff', {
                key     : that.searchstaffVal,
                page    : 1,
                pageSize: 1000000
            }).then(res => {
                if (res.code === 1) {
                    that.myGroupAllList = res.data.data;
                }
            });
        },
        // 确认省市区
        regionConfirm(e) {
            this.area_text = `${e[0].label}${e[1].label}${e[2].label}`;
        },
        changeedit() {
            this.currentPage = 1;
            this.mykehuList  = [];
            this.getmyKehuList()
        },
        chooseRegion() {

        },
        telphone(num) {
            this.showTetel = true;
            this.telenum   = num
        },
        // 初始化
        init() {
            this.isRefresh = false;
        },

        // 路由跳转
        jump(path, parmas) {
            console.log('-----11111');
            this.$Router.push({
                path : path,
                query: parmas
            });
        },
        // 客户列表
        getmyKehuList() {
            let that = this;
            that.$http('login.customers', {
                address       : that.area_text,
                customer_phone: that.searchVal,
                page          : that.currentPage,
                pagesize      : 10
            }, '加载中···').then(res => {
                if (res.code === 1) {
                    res.data.data.map((item, index) => {
                        item.car_tag        = item.car.split(',')
                        let phone           = JSON.parse(JSON.stringify(item.phone))
                        item.phones         = phone.replace(/^(\d{3})\d{4}(\d+)/, "$1****$2");
                        item.customer_names = item.customer_name.charAt(0) + that.idCard(item.idcard)
                    })
                    that.mykehuList = [...that.mykehuList, ...res.data.data];
                    console.log("====that.mykehuList", that.mykehuList)
                    that.isEmpty    = !that.mykehuList.length;
                    that.lastPage   = res.data.last_page;
                    that.loadStatus = that.currentPage < res.data.last_page ? 'loadmore' : 'nomore';
                    this.total      = res.data.total
                }
            });
        },
        //通过身份证号计算性别
        idCard(userCard) {
            //获取性别
            if (parseInt(userCard.substr(16, 1)) % 2 == 1) {
                return "男士";
            } else {
                return "女士";
            }

        }


    }
};
</script>

<style lang="scss">
.home-wrap {
    padding: 0 30rpx 30rpx;
}

.bianji {
    width: 90%;
    background: #0081ff;
    border-radius: 30rpx;
    color: #fff;
}

.input-item {
    color: #333;
    margin: 20rpx 0rpx 20rpx 20rpx;
    height: 64rpx;
    background: #FFFFFF;
    border-radius: 30rpx;
    text-indent: 14rpx;
}

//nav
.collect-list{
    .zixun-item {
        border-radius: 20rpx;
        background: #fff;

        .zixuntitle {
            font-size: 28rpx;
            color: #333;
            font-weight: bold;
        }

        .zixunimg {
            width: 100%;
            height: 180rpx;

            image {
                width: 100%;
                height: 100%;
            }
        }

        .zixuntime {
            color: #cccccc;
            font-size: 24rpx;
        }

        .yichu {
            padding: 16rpx 26rpx;
            border-radius: 34rpx;
            background: #0081ff;
            color: #fff;
        }

        .tag {
            color: #fff;
            padding: 6rpx 18rpx;
            font-size: 20rpx;
            border-radius: 20rpx;
            border: 2rpx solid transparent;
            margin-right: 10rpx;
        }
    }
}

.userInfo {
    .userleft {
        .usertitle {
            font-size: 28rpx;
        }
    }

    .userright {
        padding: 10rpx 24rpx;
        background: #0081ff;
        border-radius: 30rpx;
        color: #FFFFFF;
    }

}

.userright {
    padding: 10rpx 24rpx;
    background: #0081ff;
    border-radius: 30rpx;
    color: #FFFFFF;
}

// 提示
.notice-modal {
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    align-items: center;
    width: 85vw;
    min-height: 358rpx;
    background: #ffffff;
    padding: 30rpx;
    border-radius: 20rpx;

    .notice-title {
        width: 100%;
        font-size: 30rpx;
        font-weight: bold;
        color: #46351b;
        text-align: center;
    }

    .notice-detail {
        font-size: 24rpx;
        font-weight: 400;
        color: #999999;
        line-height: 36rpx;
        margin-bottom: 50rpx;
    }

    .back-btn {
        width: 45%;
        height: 70rpx;
        line-height: 70rpx;
        background: #f8f8f8;
        box-shadow: 0 7rpx 8rpx 2rpx #ccc;
        border-radius: 35rpx;
        font-size: 26rpx;
        font-weight: 500;
        color: #333;
        margin-bottom: 10rpx;
    }

    .notice-btn {
        width: 45%;
        height: 70rpx;
        line-height: 70rpx;
        font-size: 26rpx;
        font-weight: 500;
        color: #fff;
        border-radius: 35rpx;
        background: linear-gradient(90deg, #3357DB 0%, #3469E1 47%, #3597F1 100%);
        box-shadow: 0 7rpx 8rpx 2rpx #3597F1;
    }
}

.modal-content {
    padding: 0 30rpx;


}

// 弹窗
.modal-box {
    width: 750rpx;
    border-radius: 30rpx 30rpx 0 0;
    background: #fff;

    .modal-head {
        height: 92rpx;
        border-bottom: 1px solid rgba(223, 223, 223, 0.5);
        padding: 0 30rpx;

        .head-title {
            font-size: 32rpx;
            font-weight: bold;
        }
    }

    .modal-content {
        padding: 0 30rpx;

        .into-item {
            width: 100%;
            padding: 10rpx 0;
            color: #333;
            border-radius: 30rpx;
            display: flex;
            justify-content: center;
            align-items: center;
        }
    }

    .modal-foot {
        font-size: 24rpx;
        padding: 20rpx 0;
        font-weight: 500;
        color: rgba(153, 153, 153, 1);
        border-top: 1px solid rgba(223, 223, 223, 0.5);

        .back-btn {
            width: 45%;
            height: 70rpx;
            line-height: 70rpx;
            background: #f8f8f8;
            box-shadow: 0 7rpx 8rpx 2rpx #ccc;
            border-radius: 35rpx;
            font-size: 28rpx;
            font-weight: 500;
            color: #333;
            margin-bottom: 10rpx;
        }

        .notice-btn {
            width: 45%;
            height: 70rpx;
            line-height: 70rpx;
            font-size: 28rpx;
            font-weight: 500;
            color: #fff;
            border-radius: 35rpx;
            background: linear-gradient(90deg, #3357DB 0%, #3469E1 47%, #3597F1 100%);
            box-shadow: 0 7rpx 8rpx 2rpx #3597F1;
        }
    }
}
.yuangonglist{
    .zixun-item {
        border-radius: 20rpx;
        background: #fff;

        .zixuntitle {
            color: #333;
            font-size: 30rpx;
        }

        .zixunimg {
            width: 100%;
            height: 180rpx;

            image {
                width: 100%;
                height: 100%;
            }
        }

        .zixuntime {
            color: #cccccc;
            font-size: 24rpx;
        }

        .yichu {
            padding: 16rpx 26rpx;
            border-radius: 34rpx;
            background: #0081ff;
            color: #fff;
        }

        .tag {
            background: #fff;
            color: #5e00ff;
            padding: 10rpx 18rpx;
            font-size: 20rpx;
            border-radius: 34rpx;
            border: 2rpx solid #5e00ff;
        }
    }

}
.kehulsit {
    white-space: nowrap;
}
::v-deep .u-radio{
    min-width: 100%;
    border: 2rpx solid #f3f4f6;
    border-radius: 26rpx;
    margin-bottom: 20rpx;
}

::v-deep .u-radio__label{
    min-width: 95%;
}
::v-deep .u-checkbox__label{
    min-width: 95%;
}
.into-name{
    background: linear-gradient(90deg, #3357DB 0%, #3469E1 47%, #3597F1 100%);
    color: #fff;
    height: 60rpx;
    padding: 0 15rpx;
    display: flex;
    align-items: center;
    border-radius: 28rpx;
}
</style>
